<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script src="https://cdn.staticfile.org/jquery/1.12.3/jquery.min.js"></script>
</head>
<body>
<h1>字母哥业务系统登录</h1>
<form action="/login" method="post">
    <span>用户名称</span><input type="text" name="uname" id="username"/> <br>
    <span>用户密码</span><input type="password" name="pword"  id="password"/> <br>
    <input type="button" onclick="login()" value="登陆">
</form>

<script type="text/javascript">
    function login() {
        var username = $("#username").val();
        var password = $("#password").val();
        if (username === "" || password === "") {
            alert('用户名或密码不能为空');
            return;
        }

        $.ajax({
            type: "POST",
            url: "/login",
            data: {
                "uname": username,   //这里的参数名称要和Spring Security配置一致
                "pword": password
            },
            success: function (json) {
                if(json.isok){
                    location.href = '/'; //index.html
                }else{
                    alert(json.message);
                    location.href = '/login.html'; //index.html
                }
            },
            error: function (e) {

            }
        });
    }
</script>

</body>
</html>